<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<style>
			*{
				margin:0;
				padding: 0;
			}
			html,body{
				width:100%;
				height:100%;
			}
			.black{
				width:100%;
				height:100%;
				background: rgba(0,0,0,0.3);
				position: fixed;
				top:0;
				display: none;
			}
			.conten{
				width:500px;
				height:300px;
				background: #ccc;
				position: absolute;
				top:0;
				left:0;
				bottom: 0;
				right:0;
				margin:auto;
				border:2px solid red;
				text-align: center;
				line-height: 300px;
			}
		</style>
	</head>

	<body>
		<button>弹出</button>
		<div class="black"> 
			<div class="conten">X</div>
		</div>
	</body>
<script>
	var btn = document.getElementsByTagName("button")[0]
	var bla = document.getElementsByClassName("black")[0]
	var fan = document.getElementsByClassName("conten")[0]
	btn.onclick=function(){
		bla.style.display="block"
	}
	fan.onclick=function(){
		bla.style.display="none"
	}
</script>
</html>
